package cn.dnui_jzy913.dnuifood_16110100913.Fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.List;

import cn.dnui_jzy913.dnuifood_16110100913.Activity.MypingjiaActivity;
import cn.dnui_jzy913.dnuifood_16110100913.Activity.UpUserXinxiBean;
import cn.dnui_jzy913.dnuifood_16110100913.R;
import cn.dnui_jzy913.dnuifood_16110100913.bean.CommentsBean;
import cn.dnui_jzy913.dnuifood_16110100913.bean.UserBean;
import cn.dnui_jzy913.dnuifood_16110100913.listener.RetrofitListener;
import cn.dnui_jzy913.dnuifood_16110100913.model.UserModel;

public class Fragment4 extends BaseFragment implements RetrofitListener<UserBean> {
    private TextView username,tel,user_dizhi;
    private LinearLayout L_mypingjia,L_xxxiugai;
    private UserModel userModel;
    private UserBean userBean;
    private ImageButton btn;



    @Override
    protected int initlayout() {
        return R.layout.fragment4;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    public void onSuccess(List<CommentsBean> object, int flag) {

    }

    @Override
    void initViews() {
        username = view.findViewById(R.id.f4_username);
        tel = view.findViewById(R.id.f4_tel);
        user_dizhi = view.findViewById(R.id.f4_dizhi);
        L_mypingjia = view.findViewById(R.id.f4_mypingjia);
        L_xxxiugai = view.findViewById(R.id.f4_xiugai);

        btn = view.findViewById(R.id.img_wdpj);

    }

    @Override
    void initData() {
        userModel = new UserModel();
        userModel.getUserById(getUser_id(),this);
    }

    @Override
    void initEvents() {
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getActivity(),MypingjiaActivity.class);
                startActivity(intent);
            }
        });
        L_mypingjia.setOnClickListener(new View.OnClickListener() {//进入评价页面
            @Override
            public void onClick(View view) {
                //跳转到我的评价页面
                Intent intent = new Intent(getActivity(),MypingjiaActivity.class);
                startActivity(intent);
            }
        });

        L_xxxiugai.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //进入修改页面
                Intent intent = new Intent(getActivity(),UpUserXinxiBean.class);
                intent.putExtra("username",userBean.getUsername());
                intent.putExtra("userpass",getUser_password());
                intent.putExtra("tel",userBean.getMobilenum());
                intent.putExtra("address",userBean.getAddress());
                startActivity(intent);

            }
        });


    }


    @Override
    public void onSuccess(UserBean object, int flag) {
        this.userBean = object;
        username.setText("我的名字："+object.getUsername());
        tel.setText(object.getMobilenum());
        user_dizhi.setText(object.getAddress());
    }

    @Override
    public void onFalure() {
        showToast("网络错误");
    }

    @Override
    public void onResume() {
        super.onResume();
        initData();
    }
}

